import request from '@/utils/request'
import { HTTP_METHOD } from '@/utils/const/http/method'

const baseUrl = '/auth/cms/site/user/'

/**
 * 查询有某站点权限的用户
 *
 * @param siteId     站点
 * @return List<CmsSiteUser>
 */
export function selectUsersBySiteId (siteId) {
  return request({
    url: `${baseUrl}users/by/site/id/${siteId}`,
    method: HTTP_METHOD.GET
  })
}

/**
 * 查询某用户拥有的站点权限
 *
 * @param userId     用户id
 * @return List<CmsSiteUser>
 */
export function selectSitesByUserId (userId) {
  return request({
    url: `${baseUrl}site/by/user/id`,
    method: HTTP_METHOD.GET,
    params: {
      userId
    }
  })
}

/**
 * 获取当前编辑的站点
 *
 * @return 站点id
 */
export function getCurrentEditSiteId () {
  return request({
    url: `${baseUrl}current/edit/site/id`,
    method: HTTP_METHOD.GET
  })
}

/**
 * 设置当前编辑的站点
 *
 * @param siteId 站点id
 * @return true/false
 */
export function setCurrentEditSiteId (siteId) {
  return request({
    url: `${baseUrl}current/edit/site/id/${siteId}`,
    method: HTTP_METHOD.POST
  })
}
